<!--
 * @Description: file content
 * @Author: oooh
 * @Date: 2024-04-18 15:37:46
 * @LastEditors: oooh
 * @LastEditTime: 2024-08-05 10:11:18
 * @FilePath: \Civil_Servant_Performance_PC\src\views\work\work-plan\index.vue
-->
<template>
  <div class="app-container">
    <el-row>
      <el-col>
        <el-select v-model="queryParams.year" placeholder="请选择" @change="handleYearChange">
          <el-option v-for="item in dict.type.biz_work_year_list" :key="item.value" :label="item.label" :value="item.value"> </el-option>
        </el-select>
        <el-select v-model="queryParams.quarter" placeholder="请选择" class="ml-10" @change="handleQuarterChange">
          <el-option v-for="item in quarterOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
        </el-select>
      </el-col>
    </el-row>
    <div class="text-banner">
      <span>重点工作（共 {{ keyWorkTotal }} 条）</span>
      <el-button size="mini" type="primary" circle icon="el-icon-refresh" plain @click="getKeyWorkList" />
    </div>
    <div v-loading="keyWorkLoading">
      <div v-for="keyWork in keyWork" :key="keyWork.month">
        <div class="month-title">
          <p>
            <span class="month-mark-first">{{ keyWork.month }}</span
            >月份重点工作
            <span class="ml-20">共计</span>
            <span class="month-mark-second">{{ keyWorkMaxScore }}</span>
            分， 已分配<span class="month-mark-second">{{ keyWork.score }}</span
            >分， 剩余可分配<span class="month-mark-second">{{ keyWorkMaxScore - keyWork.score }}</span
            >分
          </p>
        </div>
        <div>
          <el-table :data="keyWork.list" border style="width: 100%">
            <el-table-column label="序号" type="index" align="center">
              <template slot-scope="scope">
                <span>{{ scope.$index + 1 }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="normName" label="指标名称" width="180" align="center">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.normName"
                  placeholder="输入指标名称"
                  v-show="!checkWorkPlanDisabled(scope.row.workAuditStatusDict)"
                ></el-input>
                <span v-show="checkWorkPlanDisabled(scope.row.workAuditStatusDict)">{{ scope.row.normName }}</span>
              </template>
            </el-table-column>
            <!-- <el-table-column prop="workNatureDict" label="工作性质" width="180" align="center">
              <template slot-scope="scope">
                <el-select
                  v-model="scope.row.workNatureDict"
                  placeholder="选择工作性质"
                  v-show="!checkWorkPlanDisabled(scope.row.workAuditStatusDict)"
                >
                  <el-option v-for="item in dict.type.biz_work_nature" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                </el-select>
                <span v-show="checkWorkPlanDisabled(scope.row.workAuditStatusDict)">{{ scope.row.workNatureDictName }}</span>
              </template>
            </el-table-column> -->
            <el-table-column prop="workContent" label="内容及方式" min-width="180" align="center">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.workContent"
                  type="textarea"
                  placeholder="输入内容及方式"
                  :rows="1"
                  :autosize="{ minRows: 1, maxRows: 5 }"
                  v-show="!checkWorkPlanDisabled(scope.row.workAuditStatusDict)"
                ></el-input>
                <div v-show="checkWorkPlanDisabled(scope.row.workAuditStatusDict)" class="pre-wrap align-left">
                  {{ scope.row.workContent || '-' }}
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="planScore" label="分值" width="120" align="center">
              <template slot-scope="scope">
                <el-input-number
                  v-model="scope.row.planScore"
                  placeholder="分值"
                  controls-position="right"
                  :min="1"
                  :max="parseInt(keyWorkMaxScore)"
                  @change="keyWorkUsedScore(keyWork.month)"
                  v-show="!checkWorkPlanDisabled(scope.row.workAuditStatusDict)"
                ></el-input-number>
                <span v-show="checkWorkPlanDisabled(scope.row.workAuditStatusDict)">{{ scope.row.planScore }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="workCreateDate" label="创建日期" width="160" align="center">
              <template slot-scope="scope">
                <el-date-picker
                  v-model="scope.row.workCreateDate"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期"
                  v-show="!checkWorkPlanDisabled(scope.row.workAuditStatusDict)"
                  :clearable="false"
                >
                </el-date-picker>
                <span v-show="checkWorkPlanDisabled(scope.row.workAuditStatusDict)">{{ scope.row.workCreateDate }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="name" label="操作" align="center" width="140" fixed="right">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  v-show="checkBtnVisible('revocation', scope.row.workAuditStatusDict)"
                  class="color-warning"
                  size="mini"
                  @click.stop="handleWorkPlanRevocation(scope.row, 'keyWork')"
                  v-hasPermi="['work:work-plan:revocation']"
                  :disabled="!isWorkEdit"
                >
                  [审核中]点击撤回
                </el-button>
                <ApprovalLog :biz-id="scope.row.id" v-show="checkBtnVisible('approval', scope.row.workAuditStatusDict)">
                  <el-button type="text" class="color-warning" size="mini"> [审核中] </el-button>
                </ApprovalLog>
                <ApprovalLog :biz-id="scope.row.id" v-show="checkBtnVisible('finish', scope.row.workAuditStatusDict)">
                  <el-button type="text" size="mini" class="color-success" icon="el-icon-check">[审核通过]</el-button>
                </ApprovalLog>

                <ApprovalLog :biz-id="scope.row.id" v-show="checkBtnVisible('resubmit', scope.row.workAuditStatusDict)">
                  <el-button
                    type="text"
                    icon="el-icon-warning-outline"
                    size="mini"
                    @click.stop="handleWorkPlanSaveOrSubmit(scope.row, 'keyWork', 'submit')"
                    class="color-danger"
                    v-hasPermi="['work:work-plan:submit']"
                    :disabled="!isWorkEdit"
                  >
                    [被退回]重新提交
                  </el-button>
                </ApprovalLog>
                <el-button
                  type="text"
                  v-show="checkBtnVisible('save', scope.row.workAuditStatusDict, scope.row.workSubmitMark)"
                  size="mini"
                  @click.stop="handleWorkPlanSaveOrSubmit(scope.row, 'keyWork', 'save')"
                  v-hasPermi="['work:work-plan:save']"
                  :disabled="!isWorkEdit"
                >
                  保存
                </el-button>

                <el-button
                  type="text"
                  v-show="checkBtnVisible('submit', scope.row.workAuditStatusDict, scope.row.workSubmitMark)"
                  size="mini"
                  @click.stop="handleWorkPlanSaveOrSubmit(scope.row, 'keyWork', 'submit')"
                  v-hasPermi="['work:work-plan:submit']"
                  :disabled="!isWorkEdit"
                >
                  提交
                </el-button>
                <el-button
                  type="text"
                  v-show="scope.row.id && checkBtnVisible('remove', scope.row.workAuditStatusDict, scope.row.workSubmitMark)"
                  size="mini"
                  @click.stop="handleWorkPlanRemove(scope.row, 'keyWork')"
                  v-hasPermi="['work:work-plan:remove']"
                  :disabled="!isWorkEdit"
                >
                  删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>

    <div class="text-banner mt-45">
      <span>中心工作（共 {{ centerWorkTotal }} 条）</span>
      <el-button size="mini" type="primary" circle icon="el-icon-refresh" plain @click="getCenterWorkList" />
    </div>
    <div v-loading="centerWorkLoading">
      <div v-for="work in centerWork" :key="work.quarter">
        <div class="month-title">
          <p>
            <span class="month-mark-first">{{ work.quarter }}</span>
            季度中心工作
            <!-- <span class="ml-20">共计</span>
            <span class="month-mark-second">{{ centerWorkMaxScore }}</span> 分， 已分配<span class="month-mark-second">
              {{ work.score }}
            </span>
            分， 剩余<span class="month-mark-second">{{ centerWorkMaxScore - work.score }}</span>
            分 -->
          </p>
        </div>
        <div>
          <el-table :data="work.list" border style="width: 100%">
            <el-table-column label="序号" type="index" align="center">
              <template slot-scope="scope">
                <span>{{ scope.$index + 1 }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="normName" label="指标名称" width="180" align="center">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.normName"
                  placeholder="输入指标名称"
                  v-show="!checkWorkPlanDisabled(scope.row.workAuditStatusDict)"
                ></el-input>
                <span v-show="checkWorkPlanDisabled(scope.row.workAuditStatusDict)">{{ scope.row.normName }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="workContent" label="指标打分说明" min-width="180" align="center">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.workContent"
                  type="textarea"
                  placeholder="输入指标打分说明"
                  :rows="1"
                  :autosize="{ minRows: 1, maxRows: 5 }"
                  v-show="!checkWorkPlanDisabled(scope.row.workAuditStatusDict)"
                ></el-input>
                <div v-show="checkWorkPlanDisabled(scope.row.workAuditStatusDict)" class="pre-wrap align-left">{{ scope.row.workContent }}</div>
              </template>
            </el-table-column>
            <el-table-column prop="deptName" label="责任单位" align="center" show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{ scope.row.deptName }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="planScore" label="分值" width="80" align="center">
              <template slot-scope="scope">
                <span>{{ isNaN(scope.row.planScore) || scope.row.planScore === null ? '-' : scope.row.planScore }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="workCreateDate" label="创建日期" width="160" align="center">
              <template slot-scope="scope">
                <el-date-picker
                  v-model="scope.row.workCreateDate"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期"
                  v-show="!checkWorkPlanDisabled(scope.row.workAuditStatusDict)"
                  :clearable="false"
                >
                </el-date-picker>
                <span v-show="checkWorkPlanDisabled(scope.row.workAuditStatusDict)">{{ scope.row.workCreateDate }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="name" label="操作" align="center" width="140" fixed="right">
              <template slot-scope="scope">
                <div v-if="scope.row.createMark">
                  <el-button
                    type="text"
                    v-show="checkBtnVisible('revocation', scope.row.workAuditStatusDict)"
                    class="color-warning"
                    size="mini"
                    @click.stop="handleWorkPlanRevocation(scope.row, 'centerWork')"
                    v-hasPermi="['work:work-plan:revocation']"
                    :disabled="!isWorkEdit"
                  >
                    [审核中]点击撤回
                  </el-button>
                  <ApprovalLog :biz-id="scope.row.id" v-show="checkBtnVisible('approval', scope.row.workAuditStatusDict)">
                    <el-button type="text" class="color-warning" size="mini"> [审核中] </el-button>
                  </ApprovalLog>
                  <ApprovalLog :biz-id="scope.row.id" v-show="checkBtnVisible('finish', scope.row.workAuditStatusDict)">
                    <el-button type="text" size="mini" class="color-success" icon="el-icon-check">[审核通过]</el-button>
                  </ApprovalLog>
                  <ApprovalLog :biz-id="scope.row.id" v-show="checkBtnVisible('resubmit', scope.row.workAuditStatusDict)">
                    <el-button
                      type="text"
                      icon="el-icon-warning-outline"
                      size="mini"
                      @click.stop="handleWorkPlanSaveOrSubmit(scope.row, 'centerWork', 'submit')"
                      class="color-danger"
                      v-hasPermi="['work:work-plan:submit']"
                      :disabled="!isWorkEdit"
                    >
                      [被退回]重新提交
                    </el-button>
                  </ApprovalLog>
                  <el-button
                    type="text"
                    v-show="checkBtnVisible('save', scope.row.workAuditStatusDict, scope.row.workSubmitMark)"
                    size="mini"
                    @click.stop="handleWorkPlanSaveOrSubmit(scope.row, 'centerWork', 'save')"
                    v-hasPermi="['work:work-plan:save']"
                    :disabled="!isWorkEdit"
                  >
                    保存
                  </el-button>

                  <el-button
                    type="text"
                    v-show="checkBtnVisible('submit', scope.row.workAuditStatusDict, scope.row.workSubmitMark)"
                    size="mini"
                    @click.stop="handleWorkPlanSaveOrSubmit(scope.row, 'centerWork', 'submit')"
                    v-hasPermi="['work:work-plan:submit']"
                    :disabled="!isWorkEdit"
                  >
                    提交
                  </el-button>
                  <el-button
                    :disabled="!isWorkEdit"
                    type="text"
                    v-show="scope.row.id && checkBtnVisible('remove', scope.row.workAuditStatusDict, scope.row.workSubmitMark)"
                    size="mini"
                    @click.stop="handleWorkPlanRemove(scope.row, 'centerWork')"
                    v-hasPermi="['work:work-plan:remove']"
                  >
                    删除
                  </el-button>
                </div>
                <span v-else>-</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { list as listPlan, revocation, remove, add as addPlan, update as updatePlan } from '@/api/work/work-plan'
import { quarterFormat, quarterToMonth, checkQuarterWorkEdit } from '@/utils/quarter.js'
import { getConfigKey } from '@/api/system/config'
import { getDicts } from '@/api/system/dict/data.js'
import dayjs from 'dayjs'
import { mapGetters } from 'vuex'
import ApprovalLog from '@/components/ApprovalLog'

export default {
  name: 'work-plan',
  props: {},
  dicts: ['biz_work_year_list', 'biz_work_nature', 'biz_work_score_type'],
  components: { ApprovalLog },
  data() {
    return {
      // 当前季度是否可编辑工作
      isWorkEdit: false,
      // 重点工作映射项
      keyWorkMapping: {
        normName: '指标名称',
        // workNatureDict: '工作性质',
        workContent: '内容及方式',
        planScore: '分值',
        workCreateDate: '创建日期'
      },
      keyWorkItem: {
        normName: undefined,
        // workNatureDict: undefined,
        workContent: undefined,
        planScore: undefined,
        workCreateDate: dayjs().format('YYYY-MM-DD'),
        workType: 'ZDGZ'
      },
      keyWorkMaxCount: 0,
      keyWorkTotal: 0,
      keyWork: [],
      keyWorkMaxScore: 0, // 重点工作最大分值
      keyWorkLoading: false,
      // 中心工作映射项
      centerWorkMapping: { normName: '指标名称', workContent: '指标打分说明', workCreateDate: '创建日期' },
      centerWorkItem: {
        normName: undefined,
        workContent: undefined,
        planScore: null,
        workCreateDate: dayjs().format('YYYY-MM-DD'),
        workType: 'ZXGZ',
        createMark: true,
        deptName: ''
      },
      centerWorkTotal: 0,
      centerWork: [],
      centerWorkMaxScore: 0, // 中心工作最大分值
      centerWorkLoading: false,
      quarterOptions: [],
      queryParams: {
        year: '',
        quarter: ''
      }
    }
  },
  computed: {
    ...mapGetters(['dept'])
  },
  watch: {
    dept: {
      deep: true,
      immediate: true,
      handler(val) {
        this.centerWorkItem.deptName = this.dept?.deptName
      }
    }
  },
  created() {
    this.getWorkScore()
    this.getKeyWorkCount()
    this.handleYearChange(new Date().getFullYear())
  },
  methods: {
    // 审核提示内容格式输出
    aduitContentFormat(raw) {
      let content = []
      content.push(`<p>审核意见：${raw.auditRemark || ' - '}</p>`)
      content.push(`<p>审核时间：${raw.auditTime || ' - '}</p>`)
      return content.join('')
    },
    // 校验按钮显示
    // 功能类型、审核状态、提交状态
    checkBtnVisible(type, audit, submit) {
      switch (type) {
        case 'revocation':
          // 撤回
          return audit === 'DSH'
        case 'submit':
          // 提交
          return !submit && audit !== 'SHBTG'
        case 'save':
        case 'remove':
          // 保存 && 删除
          return !submit
        case 'resubmit':
          // 退回重新提交
          return audit === 'SHBTG'
        case 'finish':
          // 审核通过
          return audit === 'SHTG'
        case 'approval':
          // 审核中（不可撤回）
          return audit === 'SHZ'
        default:
          break
      }
    },
    // 校验工作计划表单字段是否可填
    checkWorkPlanDisabled(audit) {
      let audits = ['SHTG', 'DSH', 'SHZ']
      if (audits.indexOf(audit) !== -1) {
        return true
      }
      return false
    },
    // 工作删除
    handleWorkPlanRemove(raw, workType) {
      let removeContent = `您正在删除 【${raw.normName}】 工作计划`
      if (workType === 'keyWork') {
        removeContent = `您正在删除 【${raw.month}月份-${raw.normName}】 重点工作计划`
      } else if (workType === 'centerWork') {
        removeContent = `您正在删除 【${raw.quarter}季度-${raw.normName}】 中心工作计划`
      }
      this.$confirm(`${removeContent}，数据删除后将无法找回，请确认删除`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'error',
        beforeClose: (action, instance, done) => {
          if (action === 'confirm') {
            const loading = this.$loading({
              target: '.el-message-box',
              lock: true,
              text: '正在删除...',
              spinner: 'el-icon-loading',
              background: 'rgba(255,255,255,0.6)'
            })
            remove({ id: raw.id })
              .then(() => {
                loading.close()
                if (workType === 'keyWork') {
                  this.getKeyWorkList()
                } else if (workType === 'centerWork') {
                  this.getCenterWorkList()
                } else {
                  this.getList()
                }
                this.$modal.msgSuccess('已删除')
                done()
              })
              .catch(() => {
                loading.close()
                done()
              })
          } else {
            done()
          }
        }
      })
    },
    // 工作计划保存或提交校验
    handleWorkPlanSaveOrSubmitCheck(raw, workType) {
      let mapping = {}
      let isScore = false
      if (workType === 'keyWork') {
        mapping = this.keyWorkMapping
        const score = this.keyWork.find(item => item.month == raw.month)['score']
        isScore = parseInt(score) > this.keyWorkMaxScore
      } else if (workType === 'centerWork') {
        mapping = this.centerWorkMapping
        // const score = this.centerWorkUsedScore
        // isScore = parseInt(score) > this.centerWorkMaxScore
      }
      for (let key of Object.keys(mapping)) {
        if (!raw[key]) {
          this.$message.error(`操作失败，【${mapping[key]}】 不能为空！`)
          return
        }
        if (key === 'planScore') {
          if (isScore) {
            this.$message.error(`操作失败，超出剩余可分配分值，请修改！`)
            return
          }
        }
      }

      let mustItem = {}
      let params = { year: this.queryParams.year, quarter: this.queryParams.quarter }
      if (raw.id) params.id = raw.id
      // 根据工作类型填充对应参数
      if (workType === 'keyWork') {
        for (let key of Object.keys(this.keyWorkItem)) {
          mustItem[key] = raw[key]
        }
        params = { ...params, month: raw.month, ...mustItem }
      } else if (workType === 'centerWork') {
        for (let key of Object.keys(this.centerWorkItem)) {
          mustItem[key] = raw[key]
        }
        params = { ...params, ...mustItem }
      }
      return params
    },
    // 工作计划保存或提交
    async handleWorkPlanSaveOrSubmit(raw, workType, operationType = 'save') {
      let params = await this.handleWorkPlanSaveOrSubmitCheck(raw, workType, operationType)
      if (!params) return
      params.workSubmitMark = false

      if (operationType === 'submit') {
        params.workSubmitMark = true
      }

      if (raw.id) {
        // 更新
        await updatePlan(params).then(res => {
          if (operationType === 'save') {
            this.$modal.msgSuccess('工作计划已更新')
          } else if (operationType === 'submit') {
            this.$modal.msgSuccess('工作计划已提交')
          }
        })
      } else {
        // 新增
        await addPlan(params).then(res => {
          if (operationType === 'save') {
            this.$modal.msgSuccess('工作计划已添加')
          } else if (operationType === 'submit') {
            this.$modal.msgSuccess('工作计划已提交')
          }
        })
      }

      if (workType === 'keyWork') {
        this.getKeyWorkList()
      } else if (workType === 'centerWork') {
        this.getCenterWorkList()
      } else {
        getList()
      }
    },
    // 工作计划撤回
    handleWorkPlanRevocation(raw, workType) {
      revocation({ id: raw.id }).then(res => {
        this.$modal.msgSuccess('已撤回')
        if (workType === 'keyWork') {
          this.getKeyWorkList()
        } else if (workType === 'centerWork') {
          this.getCenterWorkList()
        } else {
          getList()
        }
      })
    },
    // 中心工作已使用分值
    centerWorkUsedScore(quarter) {
      const index = this.centerWork.findIndex(item => item.quarter == quarter)
      const sum = this.centerWork[index].list.reduce((prev, curr) => {
        if (curr.planScore) {
          return prev + parseInt(curr.planScore)
        } else {
          return prev
        }
      }, 0)
      this.$set(this.centerWork[index], 'score', sum)
    },
    // 重点工作已使用分值
    keyWorkUsedScore(month) {
      const index = this.keyWork.findIndex(item => item.month == month)
      const sum = this.keyWork[index].list.reduce((prev, curr) => {
        if (curr.planScore) {
          return prev + parseInt(curr.planScore)
        } else {
          return prev
        }
      }, 0)
      this.$set(this.keyWork[index], 'score', sum)
    },
    // 获取工作分数限制
    getWorkScore() {
      getDicts('biz_dept_norm_config').then(res => {
        let { data } = res
        this.keyWorkMaxScore = data.find(item => item.dictValue === 'ZDGZ')?.remark
        this.centerWorkMaxScore = data.find(item => item.dictValue === 'ZXGZ')?.remark
      })
    },
    // 重点工作最大数量
    getKeyWorkCount() {
      getConfigKey('biz.work.importantWork.maxQuantity').then(res => {
        this.keyWorkMaxCount = res.msg
      })
    },
    // 年度选择
    handleYearChange(year) {
      this.queryParams.year = year
      // 获取当前季度、季度列表（往年默认第一季度）
      let { quarter, quarterList } = quarterFormat(year)
      this.quarterOptions = quarterList
      this.handleQuarterChange(quarter)
    },
    // 季度选择
    async handleQuarterChange(quarter) {
      this.queryParams.quarter = quarter
      // 获取季度对应月份
      this.keyWork = quarterToMonth(quarter).map(month => {
        return { month, score: 0, list: [] }
      })
      await checkQuarterWorkEdit({ year: this.queryParams.year, quarter }).then(res => {
        this.isWorkEdit = res
      })
      this.getList()
    },
    getList() {
      this.getKeyWorkList()
      this.getCenterWorkList()
    },
    // 列表排序
    listSort(list) {
      const sortOrder = { DSH: 1, SHBTG: 2, SHTG: 3 }
      // 按照 sort 字段的顺序排序
      list.sort((a, b) => {
        return sortOrder[a.workAuditStatusDict] - sortOrder[b.workAuditStatusDict]
      })
    },
    // 中心工作列表
    getCenterWorkList() {
      this.centerWorkLoading = true
      listPlan({ ...this.queryParams, workType: 'ZXGZ' })
        .then(res => {
          this.centerWorkLoading = false
          let { rows, total } = res
          this.centerWorkTotal = total
          this.centerWork = [{ score: 0, quarter: this.queryParams.quarter, list: rows }]
          this.listSort(this.centerWork[0].list)
          // 添加空项
          if (this.isWorkEdit) this.centerWork[0].list.unshift(JSON.parse(JSON.stringify(this.centerWorkItem)))

          this.centerWorkUsedScore(this.queryParams.quarter)
        })
        .catch(err => (this.centerWorkLoading = false))
    },
    // 重点工作列表
    getKeyWorkList() {
      this.keyWorkLoading = true
      listPlan({ ...this.queryParams, workType: 'ZDGZ' })
        .then(res => {
          let { rows, total } = res
          this.keyWorkTotal = total

          // 筛选季度对应月份数据
          this.keyWork.forEach((item, index) => {
            this.keyWorkLoading = false
            this.keyWork[index].list = rows.filter(work => item.month == work.month)
            // 获取到列表数据手动计算值情况
            this.keyWorkUsedScore(this.keyWork[index].month)
            this.listSort(this.keyWork[index].list)
            // 重点工作数量没有超过最大数量，新增一条空数据
            if (this.keyWork[index].list.length < this.keyWorkMaxCount && this.isWorkEdit && this.keyWork[index].score < this.keyWorkMaxScore) {
              this.keyWork[index].list.push(JSON.parse(JSON.stringify({ ...this.keyWorkItem, month: this.keyWork[index].month })))
            }
          })
        })
        .catch(err => (this.keyWorkLoading = false))
    }
  }
}
</script>

<style lang="scss" scoped>
@import url('~@/assets/styles/work.scss');
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: auto;
}

::v-deep .el-input-number--medium {
  width: auto;
}

::v-deep .el-button [class*='el-icon-'] + span {
  margin-left: 0;
}
</style>
